package com.example.myapplication.tack_10;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.myapplication.R;
import com.example.myapplication.tack_10.adapter.ArrangeAdapter;
import com.example.myapplication.tack_10.adapter.FenLeiSuQiuAdapter;
import com.example.myapplication.tack_10.data.FenLeiShuQiuData;
import com.example.myapplication.tack_10.data.XQData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;

import java.util.List;

public class FenLeiShuQiuActivity extends AppCompatActivity {
    private ImageView exit;
    private RecyclerView list;
    private List<FenLeiShuQiuData.RowsDTO> listArrange;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_10_activity_fen_lei_shu_qiu);
        init();
        exit_();
        Intent intent = getIntent();
        String id = intent.getStringExtra(Common.COMMON);
        getFenLeiShuQiu(id);
    }

    private void getFenLeiShuQiu(String id) {
        String url = "prod-api/api/gov-service-hotline/appeal/list?appealCategoryId="+id+"&pageNum=1&pageSize=10";
        OkHttpTool.doNetRequest(url, OkHttpTool.GET, FenLeiShuQiuData.class, new OkHttpTool.NetCallback() {
            @Override
            public void onSuccess(Object obj) {
                FenLeiShuQiuData xQData = (FenLeiShuQiuData)obj;
                listArrange = xQData.getRows();
                if(xQData.getCode() == 200){
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            shuQiuAdapter(xQData);
                        }


                    });
                }

            }

            @Override
            public void onFailure(String msg) {
            }
        });
    }

    private void shuQiuAdapter(FenLeiShuQiuData xQData) {
        FenLeiSuQiuAdapter arrangeAdapter = new FenLeiSuQiuAdapter(listArrange, FenLeiShuQiuActivity.this);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(FenLeiShuQiuActivity.this);
        list.setAdapter(arrangeAdapter);
        list.setLayoutManager(linearLayoutManager);
    }

    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FenLeiShuQiuActivity.this.finish();
            }
        });
    }

    private void init() {
        exit = findViewById(R.id.exit);
        list = findViewById(R.id.list);



    }
}